package org.unt.logic;

public class MathLogic {

    public static double round2Decimals(double d) {
        return roundToDecimals(d, 2);
    }

    public static double roundToDecimals(double d, int c) {

        long l = (long) ((d * Math.pow(10, c)));
        return (((double) l) / Math.pow(10, c));
    }

    public static boolean equalsWithError(double a, double b) {
        return equalsWithError(a, b, 0.1);
    }

    public static boolean equalsWithError(double a, double b, double error) {

        return Math.abs(a - b) < error;
    }

    public static String toDecimalPoint(String number) {

        if (number != null && number.indexOf(",") > -1) {
            return number.replace(',', '.');
        } else {
            return number;
        }
    }

}
